From 4a6658b0faf1ece6183dad8578af880badee98ba Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Tue, 21 Feb 2012 23:42:39 +0100 Subject: [PATCH] Set infobar css classes permanently The message-type css classes must be in the widget context all the time, not only when drawing, otherwise they are not propagated to the children, for instance a label in the InfoBar must inherit the color. Add a corresponding reftest. https://bugzilla.gnome.org/show_bug.cgi?id=670555 --- gtk/gtkinfobar.c | 34 +-- tests/reftests/Makefile.am | 3 + tests/reftests/info-bar-message-types.css | 54 +++++ tests/reftests/info-bar-message-types.ref.ui | 84 +++++++ tests/reftests/info-bar-message-types.ui | 229 +++++++++++++++++++ 5 files changed, 388 insertions(+), 16 deletions(-) create mode 100644 tests/reftests/info-bar-message-types.css create mode 100644 tests/reftests/info-bar-message-types.ref.ui create mode 100644 tests/reftests/info-bar-message-types.ui diff --git a/gtk/gtkinfobar.c b/gtk/gtkinfobar.c index 88d6046fce..528625f86b 100644 --- a/gtk/gtkinfobar.c +++ b/gtk/gtkinfobar.c @@ -290,13 +290,6 @@ gtk_info_bar_draw (GtkWidget *widget, cairo_t *cr) { GtkInfoBarPrivate *priv = GTK_INFO_BAR (widget)->priv; - const char* type_class[] = { - GTK_STYLE_CLASS_INFO, - GTK_STYLE_CLASS_WARNING, - GTK_STYLE_CLASS_QUESTION, - GTK_STYLE_CLASS_ERROR, - NULL - }; if (priv->message_type != GTK_MESSAGE_OTHER) { @@ -304,20 +297,12 @@ gtk_info_bar_draw (GtkWidget *widget, context = gtk_widget_get_style_context (widget); - gtk_style_context_save (context); - - if (type_class[priv->message_type]) - gtk_style_context_add_class (context, - type_class[priv->message_type]); - gtk_render_background (context, cr, 0, 0, gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget)); gtk_render_frame (context, cr, 0, 0, gtk_widget_get_allocated_width (widget), gtk_widget_get_allocated_height (widget)); - - gtk_style_context_restore (context); } if (GTK_WIDGET_CLASS (gtk_info_bar_parent_class)->draw) @@ -1091,7 +1076,6 @@ gtk_info_bar_set_message_type (GtkInfoBar *info_bar, GtkMessageType message_type) { GtkInfoBarPrivate *priv; - AtkObject *atk_obj; g_return_if_fail (GTK_IS_INFO_BAR (info_bar)); @@ -1099,6 +1083,21 @@ gtk_info_bar_set_message_type (GtkInfoBar *info_bar, if (priv->message_type != message_type) { + GtkStyleContext *context; + AtkObject *atk_obj; + const char *type_class[] = { + GTK_STYLE_CLASS_INFO, + GTK_STYLE_CLASS_WARNING, + GTK_STYLE_CLASS_QUESTION, + GTK_STYLE_CLASS_ERROR, + NULL + }; + + context = gtk_widget_get_style_context (GTK_WIDGET (info_bar)); + + if (type_class[priv->message_type]) + gtk_style_context_remove_class (context, type_class[priv->message_type]); + priv->message_type = message_type; gtk_widget_queue_draw (GTK_WIDGET (info_bar)); @@ -1144,6 +1143,9 @@ gtk_info_bar_set_message_type (GtkInfoBar *info_bar, } } + if (type_class[priv->message_type]) + gtk_style_context_add_class (context, type_class[priv->message_type]); + g_object_notify (G_OBJECT (info_bar), "message-type"); } } diff --git a/tests/reftests/Makefile.am b/tests/reftests/Makefile.am index c592ed483a..ec63260101 100644 --- a/tests/reftests/Makefile.am +++ b/tests/reftests/Makefile.am @@ -144,6 +144,9 @@ EXTRA_DIST += \ grid-spacing3.css \ grid-spacing3.ref.ui \ grid-spacing3.ui \ + info-bar-message-types.css \ + info-bar-message-types.ref.ui \ + info-bar-message-types.ui \ inherit-and-initial.css \ inherit-and-initial.ref.ui \ inherit-and-initial.ui \ diff --git a/tests/reftests/info-bar-message-types.css b/tests/reftests/info-bar-message-types.css new file mode 100644 index 0000000000..775601c346 --- /dev/null +++ b/tests/reftests/info-bar-message-types.css @@ -0,0 +1,54 @@ +@import "reset-to-defaults.css"; + +.info { +/* FIXME: for now label does not support background */ +/* background-color: @info_bg_color;*/ + color: @info_fg_color; +} + +.warning { +/* background-color: @warning_bg_color;*/ + color: @warning_fg_color; +} + +.question { +/* background-color: @question_bg_color;*/ + color: @question_fg_color; +} + +.error { +/* background-color: @error_bg_color;*/ + color: @error_fg_color; +} + +#reference-info { + padding: 8px; + color: @info_fg_color; + background-color: @info_bg_color; + background-image: none; +} + +#reference-warning { + padding: 8px; + color: @warning_fg_color; + background-color: @warning_bg_color; + background-image: none; +} + +#reference-question { + padding: 8px; + color: @question_fg_color; + background-color: @question_bg_color; + background-image: none; +} + +#reference-error { + padding: 8px; + color: @error_fg_color; + background-color: @error_bg_color; + background-image: none; +} + +#reference-other { + padding: 8px; +} diff --git a/tests/reftests/info-bar-message-types.ref.ui b/tests/reftests/info-bar-message-types.ref.ui new file mode 100644 index 0000000000..21dd7964b6 --- /dev/null +++ b/tests/reftests/info-bar-message-types.ref.ui @@ -0,0 +1,84 @@ + + + + + False + popup + + + True + False + + + True + False + Info + reference-info + + + 0 + 0 + 1 + 1 + + + + + True + False + Warning + reference-warning + + + 0 + 1 + 1 + 1 + + + + + True + False + Question + reference-question + + + 0 + 2 + 1 + 1 + + + + + True + False + Error + reference-error + + + 0 + 3 + 1 + 1 + + + + + True + False + Other + reference-other + + + 0 + 4 + 1 + 1 + + + + + + diff --git a/tests/reftests/info-bar-message-types.ui b/tests/reftests/info-bar-message-types.ui new file mode 100644 index 0000000000..1c38d806ca --- /dev/null +++ b/tests/reftests/info-bar-message-types.ui @@ -0,0 +1,229 @@ + + + + + False + popup + + + True + False + + + True + True + False + horizontal + info + + + False + 8 + 16 + + + True + False + Info + + + True + True + 0 + + + + + + + False + 0 + vertical + 6 + end + + + + + 0 + 0 + 1 + 1 + + + + + True + True + False + horizontal + warning + + + False + 8 + 16 + + + True + False + Warning + + + True + True + 0 + + + + + + + False + 0 + vertical + 6 + end + + + + + 0 + 1 + 1 + 1 + + + + + True + True + False + horizontal + question + + + False + 8 + 16 + + + True + False + Question + + + True + True + 0 + + + + + + + False + 0 + vertical + 6 + end + + + + + 0 + 2 + 1 + 1 + + + + + True + True + False + horizontal + error + + + False + 8 + 16 + + + True + False + Error + + + True + True + 0 + + + + + + + False + 0 + vertical + 6 + end + + + + + 0 + 3 + 1 + 1 + + + + + True + True + False + horizontal + other + + + False + 8 + 16 + + + True + False + Other + + + True + True + 0 + + + + + + + False + 0 + vertical + 6 + end + + + + + 0 + 4 + 1 + 1 + + + + + + -- 2.30.2